<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Mail;
use Illuminate\Contracts\Mail\Mailer;
use phpu\calendar\Calendar;

class birthday extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'birthday:send';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle(Mailer $mailer)
    {
        Log::info("birthday:send run-----");
        $Calendar = new Calendar();
        $calendar = $Calendar->createCalendar(date('Y'), date('m'), date('d'));
        $birthday = $calendar['lunar'][1] . $calendar['lunar'][2];
        $birthdayArr = getBirthdayArr();
        foreach ($birthdayArr as $k => $r) {
            if ($k === $birthday) {
                Log::info("birthday:send run-----" . $r['name']);
                $mailer->send('birthday', ['name' => $r['name']], function ($message) {
                    $message->to('815818648@qq.com')->subject('有朋友过生日，不要忘记送上美好祝福哦~');
                });
                break;
            }
        }
    }
}
